winsafe\dxgi\com_interfaces/
idxgiobject.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::decl::*;
4use crate::dxgi::vts::*;
5use crate::kernel::privs::*;
6use crate::ole::privs::*;
7use crate::prelude::*;
8
9com_interface! { IDXGIObject: "aec22fb8-76f3-4639-9be0-28eb43a67a2e";
10	/// [`IDXGIObject`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nn-dxgi-idxgiobject)
11	/// COM interface.
12	///
13	/// Automatically calls
14	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
15	/// when the object goes out of scope.
16}
17
18impl dxgi_IDXGIObject for IDXGIObject {}
19
20/// This trait is enabled with the `dxgi` feature, and provides methods for
21/// [`IDXGIObject`](crate::IDXGIObject).
22///
23/// Prefer importing this trait through the prelude:
24///
25/// ```no_run
26/// use winsafe::prelude::*;
27/// ```
28pub trait dxgi_IDXGIObject: ole_IUnknown {
29	/// [`IDXGIObject::GetParent`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiobject-getparent)
30	/// method.
31	#[must_use]
32	fn GetParent<T>(&self) -> HrResult<T>
33	where
34		T: ole_IUnknown,
35	{
36		let mut queried = unsafe { T::null() };
37		ok_to_hrresult(unsafe {
38			(vt::<IDXGIObjectVT>(self).GetParent)(self.ptr(), pcvoid(&T::IID), queried.as_mut())
39		})
40		.map(|_| queried)
41	}
42
43	/// [`IDXGIObject::SetPrivateData`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiobject-setprivatedata)
44	/// method.
45	///
46	/// Note: a copy of the data is made.
47	fn SetPrivateData<T>(&self, name: &GUID, data: &T) -> HrResult<()>
48	where
49		T: Sized,
50	{
51		ok_to_hrresult(unsafe {
52			(vt::<IDXGIObjectVT>(self).SetPrivateData)(
53				self.ptr(),
54				pcvoid(name),
55				std::mem::size_of::<T>() as _,
56				pcvoid(data),
57			)
58		})
59	}
60
61	/// [`IDXGIObject::SetPrivateDataInterface`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiobject-setprivatedatainterface)
62	/// method.
63	fn SetPrivateDataInterface<T>(&self, obj: &T) -> HrResult<()>
64	where
65		T: ole_IUnknown,
66	{
67		ok_to_hrresult(unsafe {
68			(vt::<IDXGIObjectVT>(self).SetPrivateDataInterface)(
69				self.ptr(),
70				pcvoid(&T::IID),
71				obj.ptr(),
72			)
73		})
74	}
75}